//implement GMapTester

#include "GMapTester.h"

GMapTester GMapTester::_mapTester;

GMapTester::GMapTester(const string& testName) : GTplTester(testName)
{
}

GMapTester::~GMapTester()
{
}

GMapTester& GMapTester::instance()
{
	return _mapTester;
}

void GMapTester::testStandardMap()
{
	cout << "---------------begin standard map test--------------------" << endl;
	GMap<string, int>* testMap = new GStandMap<string, int>();
	testMap->insert("one", 1);
	testMap->insert("two", 2);
	testMap->insert("two", 22);
	testMap->insert("three", 3);
	GMap<string, int>::IterPtr itp = testMap->find("three");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("two");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("one");
	if (itp != testMap->end())
	cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	cout << "-------------------end standard map test--------------------" << endl << endl;
}

void GMapTester::testHashMap()
{
	cout << "---------------begin hash map test--------------------" << endl;
	GMap<string, int>* testMap = new GHashMap<string, int>();
	testMap->insert("one", 1);
	testMap->insert("two", 2);
	testMap->insert("two", 22);
	testMap->insert("three", 3);
	GMap<string, int>::IterPtr itp = testMap->find("three");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("two");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("one");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	cout << "-------------------end hash map test--------------------" << endl << endl;
}

void GMapTester::testStandarMultiMap()
{
	cout << "---------------begin standard multimap test--------------------" << endl;
	GMap<string, int>* testMap = new GStandMultiMap<string, int>();
	testMap->insert("one", 1);
	testMap->insert("two", 2);
	testMap->insert("two", 22);
	testMap->insert("three", 3);
	GMap<string, int>::IterPtr itp = testMap->find("three");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	GMap<string, int>::Range range = testMap->equal_range("two");
	for (itp = range.first; itp != range.last; ++itp)
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("one");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	cout << "-------------------end standard multimap test--------------------" << endl << endl;
}

#include <list>

void GMapTester::testHashMultiMap()
{
	cout << "---------------begin hash multimap test--------------------" << endl;
#if defined(USE_POCO_ALL)
	GMap<string, int>* testMap = new GHashMultiMap<string, int, std::list<int> >();
#else
	GMap<string, int>* testMap = new GHashMultiMap<string, int>();
#endif
	testMap->insert("one", 1);
	testMap->insert("two", 2);
	testMap->insert("two", 22);
	testMap->insert("three", 3);
	GMap<string, int>::IterPtr itp = testMap->find("three");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	GMap<string, int>::Range range = testMap->equal_range("two");
	for (itp = range.first; itp != range.last; ++itp)
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("one");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	cout << "-------------------end hash multimap test--------------------" << endl << endl;
}

void GMapTester::testAll()
{
	cout << "---------------begin all map test--------------------" << endl;
	GMap<string, int>* testMap = new GStandMap<string, int>();
	testMap->insert("three", 3);
	testMap->insert("four", 4);
	testMap->insert("four", 44);
	GMap<string, int>::IterPtr itp = testMap->find("three");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("four");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	testMap = new GStandMultiMap<string, int>();
	testMap->insert("three", 3);
	testMap->insert("four", 4);
	testMap->insert("four", 44);
	itp = testMap->find("three");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	GMap<string, int>::Range range = testMap->equal_range("four");
	for (itp = range.first; itp != range.last; ++itp)
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	testMap = new GHashMap<string, int>();
	testMap->insert("six", 66);
	testMap->insert("six", 6);
	testMap->insert("five", 4);
	itp = testMap->find("six");
	if (itp != testMap->end())
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("five");
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	testMap = new GHashMultiMap<string, int>();
	testMap->insert("six", 66);
	testMap->insert("six", 6);
	testMap->insert("five", 4);
	range = testMap->equal_range("six");
	for (itp = range.first; itp != range.last; ++itp)
		cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	itp = testMap->find("five");
	cout <<  itp->getKey() << "->" << itp->getValue() << endl;
	delete testMap;
	cout << "-------------------end all map test--------------------" << endl << endl;
}

void GMapTester::run()
{
	testStandardMap();
	testHashMap();
	testStandarMultiMap();
	testHashMultiMap();
	testAll();
}
